package com.da.web.dorm_repair.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.da.web.dorm_repair.entity.BedVo;
import com.da.web.dorm_repair.entity.DormRepair;
import com.da.web.dorm_repair.entity.RepairParm;
import com.da.web.dorm_repair.mapper.DormRepairMapper;
import com.da.web.dorm_repair.service.DormRepairService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author da
 * @time 2023/12/15 上午 8:03
 */
@Service
public class DormRepairServiceImpl extends ServiceImpl<DormRepairMapper, DormRepair> implements DormRepairService {

    @Override
    public IPage<DormRepair> pageList(RepairParm parm) {
        Page<DormRepair> page = new Page<>(parm.getCurrentPage(), parm.getPageSize());
        QueryWrapper<DormRepair> query = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(parm.getDormName())) {
            query.lambda().like(DormRepair::getDormName, parm.getDormName());
        }
        //根据报修时间排序
        query.lambda().orderByDesc(DormRepair::getRepairTime);
        return this.page(page, query);
    }

    @Override
    public List<String> getSelectBedNameList() {
        //获取有人居住的宿舍信息
        List<BedVo> list = this.baseMapper.getSelectBedNameList();
        List<String> names = new ArrayList<>();
        if (list != null && !list.isEmpty()) {
            list.forEach(i -> {
                String bedCode = i.getBedCode();
                String buildName = i.getBuildName();
                String name = buildName + "-" + bedCode;
                names.add(name);
            });
        }
        return names;
    }
}
